﻿CREATE PROCEDURE [dbo].[ReportProjectSummary]
	@ProjectID int,
	@StartDate datetime,
	@EndDate datetime
AS
BEGIN
select distinct p.Name as ProjectName, case when billingState.BillingStateID=3 then 'Invoiced' else 'Recorded' end as BillingState, u.FullName as UserName, p.EstDuration as EstimatedHours, pm.HourlyRate, e.EntryDate, e.Description, e.BillableHours
from EntryLog as e inner join 
	 Projects as p on e.ProjectID = p.ProjectID inner join
	 Users as u on e.UserID = u.UserID inner join
	 BillingState as billingState on e.BillingStateID = billingState.BillingStateID inner join
	 ProjectMembers as pm on p.ProjectID = pm.ProjectID and u.UserID = pm.UserID	 
where p.ProjectID = @ProjectID  and (e.EntryDate between @StartDate and @EndDate)
END